import { queryAppMenuTree } from '@/services/appMenu';

export default {
  namespace: 'appMenus', // 命名空间名字，必填
  state: {
    currentMenuTree: [],
    rootSubmenuKeys: [],
  },
  reducers: {
    save({ state }, { payload }) {
      console.log(payload);
      return { ...state, ...payload };
    },
  },
  effects: {
    *fetchAppMenuTree({ payload }, { call, put }) {
      console.log('页面触发了异步操作');
      console.log(payload);
      const json = yield call(queryAppMenuTree, { payload });
      console.log(json);
      yield put({
        type: 'save',
        payload: {
          currentMenuTree: json,
          rootSubmenuKeys: ['1', '2', '4', '7'],
        },
      });
    },
  },
  subscriptions: {},
};
